package com.lopo.pmd;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class Test<T> {

 protected T create(Class<? extends T> type, int size) throws IllegalAccessException, InstantiationException {
        if (type == ArrayList.class) {
            return (T) new ArrayList<>(size);
        }
        if (type == HashSet.class) {
            return (T) new HashSet<>(size);
        }
        if (type == LinkedList.class) {
            return (T) new LinkedList<>();
        }
        T collection = type.newInstance();
        if (collection instanceof List<?>) {
            ((ArrayList<?>) collection).ensureCapacity(size);
        }
        return collection;
    }

}